package com.gudy.engine;


import com.gudy.engine.bean.EngineConfig;
import lombok.extern.log4j.Log4j2;
import thirdpart.checksum.ByteCheckSum;
import thirdpart.codec.BodyCodec;
import thirdpart.codec.MsgCodec;

import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @Author: Tzu
 * @Date: 2020/12/20 11:45
 * @Version: 1.0
 * @Description:
 */
@Log4j2
public class EngineStartup {

    public static void main(String[] args) throws Exception {
        //加载配置文件
        String configFileName = "engine.properties";
        InputStream inputStream;
        try {
            // 配置文件在jar包同级目录下
            inputStream = new FileInputStream(System.getProperty("user.dir") + "\\" + configFileName);
            log.info("engine.properties exist in jar path");
        } catch (Exception e) {
            // 配置文件在jar包里面
            inputStream = EngineStartup.class.getResourceAsStream("/" + configFileName);
            log.info("engine.properties exist in jar file");
        }


        new EngineConfig(
                inputStream,
                new BodyCodec(),
                new ByteCheckSum(),
                new MsgCodec()
        ).startup();
    }

//    public static void main(String[] args) throws Exception {
//        new EngineConfig(
//                "engine.properties",
//                new BodyCodec(),
//                new ByteCheckSum(),
//                new MsgCodec()
//        ).startup();
//    }
}

